﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;

namespace JSExcel
{
    public static class PubFun
    {
        public static int GetRowNum(string s)
        {
            string str = "";
            for (int i = s.Length-1; i >= 0; i--)
            {
                char c = Char.ToUpper(s[i]);
                if (c < '0' || c > '9')
                {
                    return Convert.ToInt32(str);
                }
                else str = c.ToString() + str;
            }
            return 0;
        }
        public static int GetCellNum(string s)
        {
            string str = "";
            for (int i = 0; i < s.Length; i++)
            {
                char c = Char.ToUpper(s[i]);
                if (c < 'A' || c > 'Z')
                {
                    return ConvertNum(str);
                }
                else str += c.ToString();
            }
            return 0;
        }
        public static int ConvertNum(string str26)
        {
            if (string.IsNullOrEmpty(str26)) return 0;
            int n = 0;
            for (int i = str26.Length - 1, j = 1; i >= 0; i--, j *= 26)
            {
                char c = Char.ToUpper(str26[i]);
                if (c < 'A' || c > 'Z') return 0;
                n += ((int)c - 64) * j;
            }
            return n;
        }
    }
}